package cn.chia.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.chia.back.dao.IUserDAO;
import cn.chia.pojo.User;
import cn.chia.service.IUserService;

@Service
public class UserServiceImpl implements IUserService {

	private IUserDAO userDAOImpl;
	
	public List<User> findAll() throws Exception {
		return userDAOImpl.findAll();
	}

	public User findById(int userid) throws Exception {
		return userDAOImpl.findById(userid);
	}
	
	public void insert(User user) throws Exception {
		userDAOImpl.doCreate(user);
	}

	public void delete(int id) throws Exception {
		userDAOImpl.doRemove(id);
	}

	public Map<String, Object> findall(int pageNo, int pageSize, String keyword,
			String column) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("allUser", userDAOImpl.findAll(pageNo, pageSize, keyword, column));
		map.put("allCount", userDAOImpl.getAllCount(keyword, column));
		return map;
	}

	public void update(User user) throws Exception {
		userDAOImpl.doUpdate(user);
	}
	

	public User findByWid(String wid) throws Exception {
		return userDAOImpl.findByWid(wid);
	}

	
	
	@Resource(name="userDAOImpl")
	public void setUserDAOImpl(IUserDAO userDAOImpl) {
		this.userDAOImpl = userDAOImpl;
	}

	public User login(User user) throws Exception {
		User loginUser = new User();
		loginUser = userDAOImpl.login(user);
		return loginUser;
	}


}
